package com.college_career_system.controller;


import com.alibaba.fastjson.JSONObject;
import com.college_career_system.pojo.dto.RecruitDTO;
import com.college_career_system.service.RecruitService;
import com.college_career_system.utils.Constant;
import com.college_career_system.utils.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Empty
 * @since 2022-12-04
 */
@RestController
@RequestMapping("/recruit")
@CrossOrigin(origins = Constant.URL, allowCredentials = "true", maxAge = 3600)
public class RecruitController {

    @Autowired
    private RecruitService recruitService;

    /**
     * 企业查询自己所有的招聘信息
     * @param request
     * @return
     */
    @PostMapping("/selectRecruit")
    public JSONObject selectRecruit(HttpServletRequest request) {
        return recruitService.selectRecruit(request);
    }

    /**
     * 根据招聘id查询具体的招聘信息
     * @param recruitId     招聘信息的主键
     * @return
     */
    @PostMapping("/selectRecruitById")
    public JSONObject selectRecruitById(int recruitId) {
        return recruitService.selectRecruitById(recruitId);
    }

    /**
     * 根据条件查询招聘信息
     * enterpriseType（企业类型）、recruitType（招聘职位，比如前端）、location（地点），这三个可以为空，需要哪个条件就传入哪个参数
     * beginSalary、endSalary，根据薪资金额区间进行筛选，beginSalary > 0 && endSalary >= beginSalary才可以，不需要的话两个赋值0就行
     * @param enterpriseType
     * @param recruitType
     * @param beginSalary
     * @param endSalary
     * @param location
     * @return
     */
    @PostMapping("/selectRecruitByCondition")
    public JSONObject selectRecruitByCondition(HttpServletRequest request, String enterpriseType, String recruitType, int beginSalary, int endSalary, String location) {
        return recruitService.selectRecruitByCondition(request, enterpriseType, recruitType, beginSalary, endSalary, location);
    }

    /**
     * 添加招聘信息，除了招聘id，创建时间，企业id不用写，其他都要写
     * @param recruitDTO
     * @return
     */
    @PostMapping("/saveRecruit")
    public JSONObject saveRecruit(RecruitDTO recruitDTO) {
        return recruitService.saveRecruit(recruitDTO);
    }

    /**
     * 删除招聘信息，根据招聘id进行删除
     * @param request
     * @param recruitId
     * @return
     */
    @PostMapping("/deleteRecruit")
    public JSONObject deleteRecruit(HttpServletRequest request, int recruitId) {
        return recruitService.deleteRecruit(request, recruitId);
    }
}

